<?php
 /*
  * @author Luong Trong Hieu
  *
 */
?>

<script>
function validate(){
	if(accForm.udusername.value == '')
	{
		alert("Username is required!");
		event.returnValue=false;
	}
	if(!(accForm.udsex[0].checked) && !(accForm.udsex[1].checked))
	{
		alert("Sex is required!");
		event.returnValue=false;
	}
	if(accForm.udemail.value == '')
	{
		alert("Email is required!");
		event.returnValue=false;
	}
	if(accForm.udstatus.options[0].selected)
	{
		alert("Status is required!");
		event.returnValue=false;
	}
        if(accForm.udrole.value =='')
        {
                alert("Role is required!");
                event.returnValue=false;
        }
        if(accForm.udtype.value =='')
        {
                alert("Type is required!");
                event.returnValue=false;
        }
}
</script>

<div id="heading">
<?php echo $this->title; ?>
    <br />
</div>
<?php
if(!isset($_POST['submit']) && $this->id > 0)
{
?>
<div id="form">
<form action='' method='POST' name='accForm' onsubmit="validate();">
    Username: <br /> <input type='text' name='udusername'
                 value="<? echo $this->username; ?>"><br />
    Password: (Input here if you wanna change old pass) <br />
    <input type='password' name='password'><br />
    Fullname: <br />
    <input type='text' name='udfullname'
           value="<?php echo $this->fullname; ?>"><br />
    Year of Birth: <br />
    <input type="text" name="udbyear"
           value="<?php echo $this->byear; ?>"><br />
<?php
echo"Sex: <br />";

    if($this->sex == "1")
    {
        echo "<input type=radio name=udsex value=1 checked=checked> Male ";
        echo "<input type=radio name=udsex value=0> Female";
    }
    else
    {
        echo "<input type=radio name=udsex value=1> Male ";
        echo "<input type=radio name=udsex value=0 checked=checked> Female";
    }
?>
    <br />
    Email: <br /> <input type=text name='udemail'
                           value="<?php echo $this->email; ?>"><br />
    Address: <br /> <input type=text name='udaddress'
                           value="<?php echo $this->address; ?>"><br />
    Status: <select name="udstatus">
	<option value="">...</option>
	<option value="<?php echo Constant::$STATUS_AVAILABLE ?>" selected>Available</option>
	<option value="<?php echo Constant::$STATUS_DELETED ?>">Deleted</option>
	</select><br />
<?php
echo "Role: <select name='udrole'><option value=''>...</option>";
$roleOb = new RoleDAO();
$role = $roleOb->getRoleList();
$role = $role->toArray();
foreach($role as $vRole){
    if($vRole['id'] == (int)$this->role_id)
    {
        echo "<option value='$vRole[id]' selected>$vRole[name]</option>";
    }
    else
    {
        echo "<option value='$vRole[id]'>$vRole[name]</option>";
    }
}
echo "</select><br />";

echo "Type: <select name='udtype'><option value=''>...</option>";
$typeOb = new TypeDAO();
$type = $typeOb->getTypeList();
$type = $type->toArray();
foreach($type as $vType){
    if($vType['id'] == (int)$this->type_id)
    {
        echo "<option value='$vType[id]' selected>$vType[name]</option>";
    }
    else
    {
        echo "<option value='$vType[id]'>$vType[name]</option>";
    }
}
echo "</select><br />";

?>
<input type=hidden name=id value= "<?php echo $this->id;?>">
<input type=submit name=submit value=Update>
<input type=reset name=reset value=Clear!>
<?php
?>
</form>
</div>
<?php
}
echo $this->message;
?>